package com.dw.etl.core.controller;

import javax.servlet.http.HttpServletRequest;

import com.dw.etl.common.base.BaseException;
import org.springframework.beans.factory.annotation.Autowired;
import  com.dw.etl.common.base.BaseResult;
import  com.dw.etl.common.constant.CommonResultConstant;
import com.dw.etl.core.api.MdMedIndexdimtbService;
import com.dw.etl.core.bean.model.MdMedIndexdimtb;
import org.springframework.util.StringUtils;
import  com.dw.etl.common.vo.PaginationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * mdMedIndexdimtb控制器
 * Created by hozeData on 2021/07/08.
 */
@RestController
@RequestMapping("/etl/mdMedIndexdimtb/")
@Api(description="开发中", tags="开发中")
@CrossOrigin(origins = "*", maxAge = 3600)
public class MdMedIndexdimtbController {

    @Autowired
    MdMedIndexdimtbService mdMedIndexdimtbService;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.POST)
    public BaseResult findByPage(@RequestBody MdMedIndexdimtb mdMedIndexdimtb, Integer pageNum, Integer pageSize) {
        PaginationVO<MdMedIndexdimtb> pageVO = mdMedIndexdimtbService.findPageByModel(mdMedIndexdimtb, pageNum, pageSize);
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="mdMedIndexdimtb", value="实体", paramType="body", required=true, dataType="MdMedIndexdimtb")
    @RequestMapping(value="insert", method=RequestMethod.POST)
    public BaseResult insert(@RequestBody MdMedIndexdimtb mdMedIndexdimtb, HttpServletRequest request)  {
        int num = mdMedIndexdimtbService.insertSelective(mdMedIndexdimtb);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="idDmtb", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(String idDmtb, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idDmtb)){
            throw new BaseException("请选择要编辑的项");
        }
        MdMedIndexdimtb mdMedIndexdimtb = mdMedIndexdimtbService.getById(idDmtb);
        return new BaseResult(CommonResultConstant.SUCCESS, mdMedIndexdimtb);
    }

    @ApiOperation(value="修改")
    @ApiImplicitParam(name="mdMedIndexdimtb", value="实体", paramType="body", required=true, dataType="MdMedIndexdimtb")
    @RequestMapping(value="update", method=RequestMethod.POST)
    public BaseResult update(@RequestBody MdMedIndexdimtb mdMedIndexdimtb, HttpServletRequest request)  {
        int num = mdMedIndexdimtbService.updateByIdSelective(mdMedIndexdimtb);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="idDmtb", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(String idDmtb, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idDmtb)){
            throw new BaseException("请选择要删除的项");
        }
        int num = mdMedIndexdimtbService.deleteById(idDmtb);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }



}
